import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import login from '../components/login.vue'
import article from '../views/ArticleView.vue'
import logout from '../components/logout.vue'
import register  from '../components/register.vue'
import create from '../components/articleCreate.vue'
import articles from '../components/article.vue'
import ArticleView from '../views/ArticleView.vue'
import search from '../components/searchArticle.vue'
import image from "../components/imageShow.vue"
import chatIndex from "../components/chatIndex.vue"
import notice from "../components/notice.vue"
import userInform from "../components/userInform.vue"
import GroupDisplay from "../components/groupDisplay.vue"
import setUser from "../components/setUser.vue"
import articleRedict from "../components/articleRedict.vue"
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView
    },
    {
      path: '/login',
      name: 'login',
      component:login
    },
    {
      path:'/article',
      name:'article',
      component:article
    },
    {
      path:'/logout',
      name: 'logout',
      component:logout
    },
    {
      path:'/register',
      name: 'register',
      component: register
    },
    {
      path:'/articleCreate',
      name: 'articleCreate',
      component:create 
    },
    {
      path:'/articles',
      name: 'articles',
      component:articles
    },
    {
      path:"/search",
      name:"search",
      component:search
    },
    {
      path:"/image",
      name:"image",
      component:image
    },
    {
      path:"/forum",
      name:"forum",
      component:chatIndex
    },
    {
      path:"/notice",
      name:"notice",
      component:notice
    },
    {
      path:"/selfInform",
      name:"selfInform",
      component:userInform
    },
    {
      path:"/searchGroup",
      name:"searchGroup",
      component:GroupDisplay
    },
    {
      path:"/setUser",
      name:"setUser",
      component:setUser
    },
    {
      path:"/redict",
      name:"redict",
      component:articleRedict
    }
  ]
})

// router.beforeEach((to,from)=>{
//   if(to.name == 'articleCreate' && localStorage.getItem("userId") == undefined || localStorage.getItem("userId").trim.length <= 0) 
//   {
//     return {name : "login"}
//   }
// })

export default router
